﻿using System;
using System.Collections.Generic;
using System.Xml;
using MiWebSite_Core;
using WLMCoreLibrary;

namespace MWS_Main.admin.configuracion
{
    public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load( object sender, EventArgs e )
        {
            WebSiteMainConfiguration config = WebSiteMainConfiguration.GetConfig();
            List<ParametroTransformacionXML> parametros = new List<ParametroTransformacionXML>();
            parametros.Add( new ParametroTransformacionXML( "isMobile", MiWebSiteFunctions.isMobileBrowser().ToString().ToLower() ) );
            parametros.Add( new ParametroTransformacionXML( "skinPath", config.Settings["skinPath"].value ) );

            //parametros.Add(new ParametroTransformacionXML("isHome", "true"));
            if ( Request.QueryString["xml"] != null )
            {
                dbConnector ConexionDB = new dbConnector( config.Connections[0].value );
                MiWebSitePage pagina = new MiWebSitePage( ref ConexionDB );

                XmlDocument documento = new XmlDocument();
                XmlNode XMLModuloExtraido = documento.CreateElement( "Contenido" );
                pagina.Contenido = documento.CreateElement( "MiWebSiteContent" );
                XMLModuloExtraido.InnerText = form1.InnerHtml;

                pagina.Contenido.AppendChild( XMLModuloExtraido );

                string xmlportada = WLMFunctions.SerializeObject( pagina, true );
                ConexionDB.CloseConnection();
                Response.ContentType = "text/xml";
                Response.Write( xmlportada );
                Response.End();
            }
            else
            {
                string HTMLPagina = WLMFunctions.TransformXML( config.Settings["siteURL"].value + "admin/configuracion?xml=true", config.Settings["siteURL"].value + config.Settings["skinPath"].value + "index.xsl", parametros );
                Response.Write( HTMLPagina );
                Response.End();
            }
        }
    }
}